package cn.cheln.support.secret;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateCrtKey;
import java.security.interfaces.RSAPublicKey;

public class SecretUtil
{
  public String[] createKey(int paramInt)
  {
    String[] arrayOfString = new String[5];
    try
    {
      KeyPairGenerator localKeyPairGenerator = KeyPairGenerator.getInstance("RSA");
      localKeyPairGenerator.initialize(paramInt);
      KeyPair localKeyPair = localKeyPairGenerator.generateKeyPair();
      RSAPublicKey localRSAPublicKey = (RSAPublicKey)localKeyPair.getPublic();
      RSAPrivateCrtKey localRSAPrivateCrtKey = (RSAPrivateCrtKey)localKeyPair.getPrivate();
      BigInteger localBigInteger1 = localRSAPublicKey.getPublicExponent();
      BigInteger localBigInteger2 = localRSAPublicKey.getModulus();
      BigInteger localBigInteger3 = localRSAPrivateCrtKey.getPrivateExponent();
      BigInteger localBigInteger4 = localRSAPrivateCrtKey.getPrimeP();
      BigInteger localBigInteger5 = localRSAPrivateCrtKey.getPrimeQ();
      arrayOfString[0] = localBigInteger1.toString();
      arrayOfString[1] = localBigInteger2.toString();
      arrayOfString[2] = localBigInteger3.toString();
      arrayOfString[3] = localBigInteger4.toString();
      arrayOfString[4] = localBigInteger5.toString();
      return arrayOfString;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
    }
    return arrayOfString;
  }

  public String decrypt(String paramString1, String paramString2, String paramString3)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    BigInteger localBigInteger1 = new BigInteger(paramString2);
    BigInteger localBigInteger2 = new BigInteger(paramString3);
    byte[] arrayOfByte1 = new BigInteger(paramString1).modPow(localBigInteger1, localBigInteger2).toByteArray();
    int i = 0;
    while (true)
    {
      byte[] arrayOfByte2;
      if (i >= arrayOfByte1.length)
        arrayOfByte2 = new BigInteger(localStringBuffer.toString()).toByteArray();
      try
      {
        String str = URLDecoder.decode(new String(arrayOfByte2, "GBK"), "GBK");
        return str;
        localStringBuffer.append((char)arrayOfByte1[i]);
        ++i;
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException)
      {
        localUnsupportedEncodingException.printStackTrace();
      }
    }
    return null;
  }

  public String encrypt(String paramString1, String paramString2, String paramString3)
  {
    String str1 = new String();
    try
    {
      String str2 = new BigInteger(URLEncoder.encode(paramString1, "GBK").getBytes("GBK")).toString();
      BigInteger localBigInteger1 = new BigInteger(paramString2);
      BigInteger localBigInteger2 = new BigInteger(paramString3);
      String str3 = new BigInteger(str2.getBytes("UTF8")).modPow(localBigInteger1, localBigInteger2).toString();
      return str3;
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
    }
    return str1;
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.support.secret.SecretUtil
 * JD-Core Version:    0.5.2
 */